﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using XuanXiang.Infrastructure.Attr;
using XuanXiang.Infrastructure.Dto.Request;
using XuanXiang.Infrastructure.Dto.Request.Merchant;
using XuanXiang.Service.Interface;

namespace XuanXiang.Api.Admin.Controllers
{

    [ApiGroup("Admin(管理员模块)")]
    public class MerchantController : BaseController
    {
        private readonly I_Merchant_Service _merchant_Service;

        public MerchantController(I_Login_Service login_Service,I_Merchant_Service merchant_Service) : base(login_Service)
        {
            _merchant_Service = merchant_Service;
        }

       


        /// <summary>
        /// 获取商户列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Merchant(int page = 1, int limit = 10, string? key = "") {
            var result = await _merchant_Service.Get_Merchant(new Fenye_Dto() { 
            page = page,
            limit = limit,
            key = key??""
            });
            return Ok(result);
        }



        /// <summary>
        /// 新增商户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Merchant(Add_Merchant_Dto dto) {
            var result = await _merchant_Service.AddMerchant(dto);
            return Ok(result);
        }

        /// <summary>
        /// 删除商户
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Merchant(Delete_Dto dto) {
            var result =await _merchant_Service.Delete_Merchant(dto);
            return Ok(result);
        }


        /// <summary>
        /// 商户的禁用/启用
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> IsBan_Merchant(IsBan_Dto dto) {
            var result = await _merchant_Service.IsBan_Merchant(dto);
            return Ok(result);
        }

        /// <summary>
        /// 获取单个商户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Single_Merchant(string? id) {
            var result = await _merchant_Service.Get_Single_Merchant(id);
            return Ok(result);
        }

        /// <summary>
        /// 获取商户的订单列表
        /// </summary>
        /// <param name="id"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Merchant_Order(string? id,int page=1,int limit=10) {
            var result = await _merchant_Service.Get_Merchant_Order(new Fenye_Dto() { 
            id=id,
            page=page,
            limit=limit
            });
            return Ok(result);
        }
    }
}
